package com.zzzyh.bookbackgroundsystem.mapper;

import com.zzzyh.bookbackgroundsystem.pojo.Book;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BookMapper {

    @Select("SELECT * FROM `book_info`")
    public List<Book> getAllBooks();

    @Select("SELECT COUNT(*) FROM `book_info`")
    public Integer getBookCount();

    @Select("SELECT * FROM `book_info` " +
            "ORDER BY `id` ASC " +
            "LIMIT #{offset},#{count}")
    List<Book> getBooksByPage(Integer offset, Integer count);

    @Insert("INSERT INTO `book_info`(`book_name`,`author`,`count`,`price`,`publish`,`status`) " +
            "VALUES (#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer addBook(Book book);

    @Select("SELECT * FROM `book_info` WHERE `id`=#{id}")
    Book findBookById(Integer id);


    Integer updateBook(Book book);

    @Update("UPDATE `book_info` SET `status`= 5 WHERE `id`=#{id}")
    Integer deleteBook(Integer id);

}
